const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
    index: './src/index.js',
  },
  devtool: "source-map", //查看打包后的代码更方便
  mode: 'development',
  // mode: 'production',
  output: {
    clean: true,
    // publicPath: '/',
    filename: '[name].js',
    // chunkFilename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
    // library: {
    //   name: 'testbb',
    //   type: 'umd',
    // },
  },
  resolveLoader: {
    //找loader的时候，先去loaders目录下找，找不到再去node_modules下面找
    modules: ["loaders", "node_modules"],
    alias: {
      "testLoader": path.resolve(__dirname, "./loaders/index.js"),
    },
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: ["eslint-loader"],
        enforce: "pre", //编译前先对js文件进行校验
      },
      {
        test: /\.js$/,
        use: ["babel-loader"],
      },
      {
        test: /\.css$/,
        use: ["css-loader"],
        enforce: "pre",  //这里也可以是post，默认不写就是normal
      },
      {
        test: /\.less$/,
        use: [
          'style-loader', //将css内容变成style标签插入到html中去
          'css-loader', //解析css文件的路径等
          'less-loader' //将less=>css
        ]
      },
      {
        test: /\.js$/,
        use: [
          {
            loader: 'testLoader',
            options: {
              /* ... */
            },
          },
        ],
      },
      {
        test: /\.js$/,
        use: [
          {
            loader: path.resolve(__dirname, "./loaders/index.js"),
            options: {
              /* ... */
            },
          },
        ],
      },
        // {
        //   test: /\.worker\.js$/,
        //   use: {
        //     loader: 'worker-loader',
        //     options: {
        //       filename: '[name].[contenthash].js',
        //     },
        //   },
        // },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './index.html',
      title: 'index',
      filename: 'index.html',
    }),
  ],
};


